package com.whq.thrift.api.web.admin.db.baseconf;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

public interface ModuleInfoMapper {
	@Select("select * from t_module_info where module_id=#{moduleId}")
	@Results(value = { 
			@Result(property = "moduleId", column = "module_id"),
			@Result(property = "comment", column = "comment"),
			@Result(property = "owner", column = "owner"),
			@Result(property = "createTime", column = "create_time"),
			@Result(property = "updateTime", column = "update_time"), 
			@Result(property = "for_gateway", column = "for_gateway"),
			@Result(property = "err_code_min", column = "err_code_min"), 
			@Result(property = "err_code_max", column = "err_code_max"),
			@Result(property = "moduleStatus", column = "module_status"), 
			@Result(property = "servicePort", column = "service_port"), 
			@Result(property = "moduleComment", column = "module_comment") })
	public ModuleInfo getRecordByKey(@Param("moduleId") String moduleId);

	@Insert("INSERT INTO t_module_info " + " (module_id, comment, owner, create_time, update_time,"
			+ "err_code_min,err_code_max,for_gateway,module_status,service_port,module_comment) " + " VALUES "
			+ " (#{moduleId}, #{comment}, #{owner}, #{createTime}, #{updateTime},"
			+ "#{err_code_min},#{err_code_max},#{for_gateway},#{moduleStatus},#{servicePort},#{moduleComment})")
	public void addRecord(ModuleInfo moduleInfo);

	@SelectProvider(type = ModuleInfoSqlProvider.class, method = "getSelectRecordsSql")
	@Results(value = { 
			@Result(property = "moduleId", column = "module_id"), 
			@Result(property = "comment", column = "comment"),
			@Result(property = "owner", column = "owner"), 
			@Result(property = "createTime", column = "create_time"),
			@Result(property = "updateTime", column = "update_time"), 
			@Result(property = "for_gateway", column = "for_gateway"),
			@Result(property = "err_code_min", column = "err_code_min"), 
			@Result(property = "err_code_max", column = "err_code_max"),
			@Result(property = "moduleStatus", column = "module_status"), 
			@Result(property = "servicePort", column = "service_port"), 
			@Result(property = "moduleComment", column = "module_comment") })
	public List<ModuleInfo> findRecordsByMap(Map<String, Object> whereParams);

	@SelectProvider(type = ModuleInfoSqlProvider.class, method = "getSelectCountSql")
	public int findRecordsCount(Map<String, Object> whereParams);

	@UpdateProvider(type = ModuleInfoSqlProvider.class, method = "getUpdateSql")
	public void updRecord(ModuleInfo moduleInfo);

	@Delete("delete from t_module_info where module_id=#{moduleId}")
	public void delRecord(@Param("moduleId") String moduleId);

	@Select("select * from t_module_info where for_gateway=1")
	@Results(value = { 
			@Result(property = "moduleId", column = "module_id"),
			@Result(property = "comment", column = "comment"),
			@Result(property = "owner", column = "owner"), 
			@Result(property = "createTime", column = "create_time"),
			@Result(property = "updateTime", column = "update_time"), 
			@Result(property = "for_gateway", column = "for_gateway"),
			@Result(property = "err_code_min", column = "err_code_min"),
			@Result(property = "err_code_max", column = "err_code_max"),
			@Result(property = "moduleStatus", column = "module_status"),
			@Result(property = "servicePort", column = "service_port"), 
			@Result(property = "moduleComment", column = "module_comment") })
	public List<ModuleInfo> findForGatewayList();
}
